﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Foundation;

namespace G.Animation
{
    public class AnimationHelp
    {
        public static IEnumerable<Point> BezierSegment(Point pt0, Point pt1, Point pt2, Point pt3)
        {
            double x, y;
            for (double i = 0; i <= 1; i += (1.0 / 100))
            {
                x = Math.Pow(i, 3) * (pt3.X + 3 * (pt1.X - pt2.X) - pt0.X) + 3 * Math.Pow(i, 2) * (pt0.X - 2 * pt1.X + pt2.X) + 3 * i * (pt1.X - pt0.X) + pt0.X;
                y = Math.Pow(i, 3) * (pt3.Y + 3 * (pt1.Y - pt2.Y) - pt0.Y) + 3 * Math.Pow(i, 2) * (pt0.Y - 2 * pt1.Y + pt2.Y) + 3 * i * (pt1.Y - pt0.Y) + pt0.Y;
                yield return new Point(x, y);
            }
        }
        /// <summary>
        /// 求圆的匀速运动点
        /// </summary>
        /// <param name="R"></param>
        /// <returns></returns>
        public static IEnumerable<Point> ArcSegment(Point p)
        {
            double step = 90.0 / 100;
            double x = 0;
            double y = 0;
            double rotate = 0;
            while (rotate <= 360)
            {
                double a = Math.PI * rotate / 180;
                y = p.Y * Math.Sin(a);
                x = p.X * Math.Cos(a);
                rotate += step;
                yield return new Point(x, y);
            }
        }
    }
}
